package com.cheejee.goodscenter.controller;

import static com.cheejee.goodscenter.module.response.BaseReponse.addOk;
import static com.cheejee.goodscenter.module.response.BaseReponse.deleteOk;
import static com.cheejee.goodscenter.module.response.BaseReponse.changeOk;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.cheejee.goodscenter.module.entity.GoodsBrandProperties;
import com.cheejee.goodscenter.module.response.PageReponse;
import com.cheejee.goodscenter.service.GoodsBrandPropertiesService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

/**
 * @author CARRY
 * @Date 2020年11月2日上午5:41:26
 */
@RestController
@RequestMapping("/goods/brandProperties")
@Api(tags = "商品品牌属性")
public class GoodsBrandPropertiesController {

	@Resource
	private GoodsBrandPropertiesService service;
	
	@GetMapping("/{goodsId}")
	@ApiOperation("查询商品品牌属性")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "pageSize", value = "每页内容数", defaultValue = "0", dataType = "int"),
		@ApiImplicitParam(name = "pageNum", value = "页码", defaultValue = "0", dataType = "int") })
	public Object getPropertestByGoods(@PathVariable Long goodsId, Integer pageNum, Integer pageSize) {
		
		return PageReponse.ok(service.queryGoodsBrandProperties(goodsId, null, null, pageNum, pageSize));
	}
	
	@PutMapping("/")
	@ApiOperation("添加商品品牌属性")
	public Object addProperties(@RequestBody GoodsBrandProperties properties) {
		service.addGoodsBrandProperties(properties);
		
		return addOk(service.queryById(properties.getId()));
	}
	
	@PutMapping("/{id}")
	@ApiOperation(value = "修改商品品牌属性", notes = "只能修改属性值")
	public Object changeProperties(@PathVariable Long id, String value) {
		service.changeGoodsBrandPropertiesValue(id, value);
		
		return changeOk(service.queryById(id));
	}
	
	@DeleteMapping("/{id}")
	@ApiOperation("删除商品品牌属性")
	public Object deletProperties(Long[] id) {
		service.deleteGoodsBrandProperties(id);
		
		return deleteOk();
	}
	
}
